<template>
	<view class="window">
		<!-- #ifndef H5 -->
		<view class="topLine" :style="{height: topBar+'px'}"></view>
		<!-- #endif -->
		<view class="nav row_align_center" id="nav">
			<li :class="['iconfont icon-left back']" @click="gotoBack()"></li>
			<text class="title">{{title?title:''}}</text>
			<slot name="calendar"></slot>
		</view>
		<view class="data_body" :style="{height: scrollHeight}">
			<slot name="mainBody"></slot>
		</view>
	</view>
</template>

<script>
	export default{
		props:{
			title:{
				type:String,
				default:''
			}
		},
		data(){
			return{
				topBar: 17, //导航高
				scrollHeight: "100%", //数据展示体高度
			}
		},
		methods:{
			gotoBack() {
				this.$enter.navigateBack();
			},
			//获取设备信息
			async getTelephoneInfo() {
				var telephoneInfo = await this.$common.getTelephoneInfo();
				let hasHeight = 0;
				if (telephoneInfo.top >= 40) {
					this.topBar = telephoneInfo.statusBarHeight;
				}
			
				// 设置滚动高度
				const query = wx.createSelectorQuery().in(this);
				query.select('#nav').boundingClientRect();
				query.exec(res => {
					res.map((item, index) => {
						hasHeight += item.height;
					})
					this.scrollHeight = (telephoneInfo.screenHeight - hasHeight - this.topBar) + 'px';
				})
			},
			getH5Info() {
				uni.getSystemInfo({
					success: e => {
						let hasHeight = 0;
						let element = wx.createSelectorQuery().in(this);
						element.select('#nav').boundingClientRect();
						element.exec(res => {
							res.map((item, index) => {
								hasHeight += item?.height ?? 0;
							})
							this.scrollHeight = (e.screenHeight - hasHeight) + 'px';
						})
					},
					fail: (err) => {
						reject(err);
					}
				})
			}
		},
		mounted(opt){
			//#ifndef H5
			this.getTelephoneInfo();
			//#endif
			//#ifdef H5
			this.getH5Info();
			//#endif
		}
	}
</script>

<style lang="scss" scoped>
	.row_align_center {
	    display: flex;
	    flex-direction: row;
	    align-items: center;
	}
	.window{
		height: 100vh;
		overflow: hidden;
		
		.topLine {
			background-color: $primary-color;
			width: 100%;
		}
		
		.data_body {
			width: 100%;
			overflow: auto;
			text-align: center;
			color: #333333;
			background-repeat: repeat;
			background-color: #ffffff;
			position: relative;
		}
		
		.nav {
			width: 100%;
			height: 80rpx;
			background-color: $primary-color;
		
			.back {
				font-size: 40rpx!important;
				padding: 20rpx 14rpx 15rpx 14rpx;
				color: #fff;
			}
		
			.title {
				color: #fff;
				font-size: 30rpx;
				width: 80%;
				text-align: center;
			}
		
			.hidden {
				visibility: hidden;
			}
		}
	}
</style>
